package org.destiny.account.service;

import java.util.List;

import org.destiny.account.dao.CustomerDao;
import org.destiny.account.dao.DaoFactory;
import org.destiny.account.entity.Customer;

public class CustomerService {
	private CustomerDao dao;
	private static CustomerService instance;

	private CustomerService(CustomerDao dao) {
		super();
		this.dao = dao;
	}

	public static CustomerService get() {
		if (instance == null)
			instance = new CustomerService(DaoFactory.getCustomerDao());
		return instance;
	}

	public int insert(Customer customer) {
		int i = dao.insert(customer);
		DaoFactory.getSession().commit();
		return i;
	}

	public int update(Customer customer) {
		int i = dao.update(customer);
		DaoFactory.getSession().commit();
		return i;
	}

	public int delete(int id) {
		int i = dao.delete(id);
		DaoFactory.getSession().commit();
		return i;
	}

	public List<Customer> selectAll() {
		List<Customer> list = dao.selectAll();
		DaoFactory.getSession().commit();
		return list;
	}

	public int countAll() {
		int c = dao.countAll();
		DaoFactory.getSession().commit();
		return c;
	}

}